﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;

namespace Vecka1.View
{
    class GameView
    {
        private SpriteBatch m_spriteBatch;
        private SpriteBatch m_SpiritBackGround;
        private Texture2D m_texture;
        private Texture2D m_backGroundTexture;
        private KeyboardState m_oldKeyboardState;
        private float m_viewScale = 64;
        private SoundEffect m_jumpSound;

        public GameView(GraphicsDeviceManager a_manager, ContentManager a_contentLoader)
        {
            //Saves keyboard state to detect change
           
            
            m_spriteBatch = new SpriteBatch(a_manager.GraphicsDevice);

            
            m_texture = a_contentLoader.Load<Texture2D>("SkyBg");

        }

        internal void DrawLevel(Microsoft.Xna.Framework.Graphics.GraphicsDevice a_graphicsDevice, Microsoft.Xna.Framework.Vector2 a_modelPlayerPosition)
        {
            a_graphicsDevice.Clear(Microsoft.Xna.Framework.Color.White);
            
            
            m_spriteBatch.Begin();
            DrawItemAt(a_graphicsDevice, a_modelPlayerPosition);
            m_spriteBatch.End();
        }

        internal void DrawItemAt(Microsoft.Xna.Framework.Graphics.GraphicsDevice a_graphicsDevice, Microsoft.Xna.Framework.Vector2 a_modelPlayerPosition)
        {
            Vector2 scaledPosition = a_modelPlayerPosition * m_viewScale;
            int viewPlayerPositionX = (int)scaledPosition.X;

            int viewPlayerBottomPositionY = a_graphicsDevice.Viewport.Height - (int)scaledPosition.Y;

            int spriteHeight = (int)m_viewScale;
            int spriteWidth = (int)m_viewScale;

            int viewPlayerTopPositionY = viewPlayerBottomPositionY - (int)spriteHeight;

            Rectangle destRect = new Rectangle(viewPlayerPositionX, viewPlayerTopPositionY, 100, 100);
            m_spriteBatch.Draw(m_texture, destRect, Color.Red);
        }

        
    }
}
